import {
  ProFormText,
  ProFormSelect,
  ProFormTextArea,
  ProFormDatePicker,
  ProFormRadio,
} from '@ant-design/pro-form';
import { Form, AutoComplete } from 'antd';
import com from '../../../utils/common';
import df from '../../../../config/dataFormat';

const shenfenzheng_regx = new RegExp(
  /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}([0-9]|x|X)$/,
  'g',
);

export default {
  text: (name, required, defVal,width) => (
    <ProFormText
      width={width}
      key={name}
      name={name}
      label={name}
      placeholder={`请输入${name}`}
      rules={[
        {
          required: required,
          message: `请输入${name}`,
        },
      ]}
    />
  ),
  select: (name, required, defVal,width) => (
    <ProFormSelect
      key={name}
      name={name}
      label={name}
      placeholder={`请输入${name}`}
      valueEnum={com.get_select_op(defVal)}
      rules={[
        {
          required: required,
          message: `请输入${name}`,
        },
      ]}
    />
  ),
  textArea: (name, required, defVal,width) => (
    <ProFormTextArea
      width={width}
      key={name}
      name={name}
      label={name}
      placeholder={`请输入${name}`}
      rules={[
        {
          required: required,
          message: `请输入${name}`,
        },
      ]}
      fieldProps={{ rows: 5 }}
    />
  ),
  date: (name, required, defVal,width) => (
    <ProFormDatePicker key={name} name={name} label={name} />
  ),
  sfz: (name, required, defVal,width) => (
    <ProFormText
      width={width}
      key={name}
      name={name}
      label={name}
      placeholder={`请输入${name}`}
      rules={[
        {
          required: required,
          message: `请输入${name}`,
        },
        { pattern: shenfenzheng_regx, message: '请输入正确的18位数身份号码!' },
      ]}
      fieldProps={{ maxLength: 18 }}
    />
  ),
  radio: (name, required, defVal,width) => (
    <ProFormRadio.Group
      width={328}
      key={name}
      radioType="button"
      options={com.get_radio_op(defVal)}
      name={name}
      label={name}
      placeholder={`请输入${name}`}
      fieldProps={{ buttonStyle: 'solid' }}
      rules={[
        {
          required: required,
          message: `请输入${name}`,
        },
      ]}
    />
  ),
  auto: (name, required, defVal,width) => (
    <Form.Item key={name} name={name} label={name}>
      <AutoComplete
        allowClear
        style={{width:width}}
        options={defVal}
        placeholder={`请输入${name}`}
        filterOption={(inputValue, option) =>
          option.value.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1
        }
      />
    </Form.Item>
  ),
};
